Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 26th, 2012, 12:52 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile store logged in user id in database from class file

Hello all,

I am storing the user id for a record who creates it. It is working fine in aspx.cs file.

myReview.Owner = (Guid)Membership.GetUser().ProviderUserKey;

but when I use the same code in a class file in App_Code folder then it does not work and code breaks.

Is there any other way to get user id in case of class file?

Please help me I am stuck on it for a long time.

Many thanks...
Reply With Quote
  #2 (permalink)  
Old February 28th, 2012, 12:06 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

Hi sophia

what error do you receive with App_Code?

as you know Membership Provider settings are stored in web.config file. so maybe you have two web.config file in your program (in sub-directories) with different Membership settings. but I'm not sure about what I said!!

are you getting error or it does not return the right result?
Are you using Windows Authentication?
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #3 (permalink)  
Old February 28th, 2012, 02:02 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

HI I am trying to upload images using httphandler.

for this I have few settings in web.config as below.

<httpHandlers>
<remove verb="POST,GET" path="Upload.axd" />
<add verb="POST,GET" path="Upload.axd" type="Upload" />
</httpHandlers>

in aspx page I am having a control to upload files, which in turn transfers the control to the Upload.cs class in App_code folder, where code is as follows (I am logged in at the time of uploading files)



public class Upload : IHttpHandler, IRequiresSessionState
{
public Upload()
{

}

#region IHttpHandler Members

public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(HttpContext context)
{
using (ProjectEntities myEntities = new ProjectEntities())
{
MyFile myFile;
string virtualFolder = "~/Images/";
//string uploadPath = context.Server.MapPath(context.Request.Application Path + virtualFolder);
string uploadPath = context.Server.MapPath(virtualFolder);
// loop through all the uploaded files
for(int j = 0; j < context.Request.Files.Count; j++)
{
// get the current file
HttpPostedFile uploadFile = context.Request.Files[j];
// if there was a file uploded
if (uploadFile.ContentLength > 0)
{

string fileName = Guid.NewGuid().ToString();

string extension = Path.GetExtension(uploadFile.FileName);

myFile = new MyFile();
myFile.Name = uploadFile.FileName;
myFile.Url = virtualFolder + fileName + extension;
myFile.Owner = (Guid)Membership.GetUser().ProviderUserKey;

//myFile.Owner = (Guid)Membership.GetUser(HttpContext.Current.User. Identity.Name).ProviderUserKey;
myEntities.AddToMyFile(myFile);
myEntities.SaveChanges();

uploadFile.SaveAs(Path.Combine(uploadPath, fileName + extension));}

}


}
}

}



The code breaks at when storing logged in user's id. Please help me.

Thanks
Reply With Quote
  #4 (permalink)  
Old February 28th, 2012, 08:06 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

Hi sophia

I think the problem maybe with Handler-Call-Time. when your handler is called?

Code:
public void Init(HttpApplication context)
{
    context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
    context.PostAuthorizeRequest += new EventHandler(context_PostAuthorizeRequest);
}

void context_PostAuthorizeRequest(object sender, EventArgs e)
{
    throw new NotImplementedException();
}

void context_AuthorizeRequest(object sender, EventArgs e)
{
    HttpApplication context = (HttpApplication)sender;
    Rewrite(context);
}
these are two different calls: you may need to call your handler in PostAuthorizeRequest event of HttpContext object
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #5 (permalink)  
Old February 29th, 2012, 05:34 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

can you please tell me where I should update my code
Thanks
Reply With Quote
  #6 (permalink)  
Old March 2nd, 2012, 12:41 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi Imar,
kindly look here, can you please spot out the mistake.
Reply With Quote
  #7 (permalink)  
Old March 3rd, 2012, 01:15 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Kindly any one please tell me how this can be overcome?
I am struggling with this problem for many days.

Pleas help.
Thanks
Reply With Quote
  #8 (permalink)  
Old March 4th, 2012, 12:56 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

I'll send it 4 hours later. I'm busy now ...
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #9 (permalink)  
Old March 6th, 2012, 01:59 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi, are you still busy?
Reply With Quote
  #10 (permalink)  
Old March 10th, 2012, 07:46 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

OK done....
I passed id through querystring.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to query database tables depending on the logged-in user. Sapan ASP.NET 4 General Discussion 1 September 20th, 2011 02:40 PM
Read file and store it to database sparsh2010 Access VBA 3 July 17th, 2008 08:27 AM
How to store MS Word File in database kesar SQL Language 2 March 1st, 2007 06:34 AM
Setting logged in UserName to Session ID Admiral1701 ASP.NET 2.0 Professional 10 December 1st, 2006 10:35 AM
how to store text file in database vivekkumar_23 Servlets 1 February 13th, 2006 05:29 AM



All times are GMT -4. The time now is 06:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.