Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Global.asax HELP

  Asked By: Ray    Date: Apr 03    Category: Sharepoint    Views: 2320

I am trying to get the user's SID by determining who is logged in and
storing that into a cookie. I am trying to do this inside the
global.asax file, but it breaks when it tries to create the SPWeb
object. Can someone please tell me what I am doing wrong?

<%@ Assembly Name="Microsoft.SharePoint"%>
<%@ Application Language="C#"
Inherits="Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication" %
>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{

//Create a new cookie, passing the name into the constructor
HttpCookie cookie = new HttpCookie("MOSS_USER");


SPWeb mySite = SPControl.GetContextWeb(Context);
SPUser myUser = mySite.CurrentUser;
string strUserSID = myUser.Sid;


//Set the cookies value
cookie.Value = strUserSID;

//Set the cookie to expire in 1 minute
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(1, 0, 0, 0);
cookie.Expires = dtNow + tsMinute;

//Add the cookie
Response.Cookies.Add(cookie);


}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the
sessionstate mode
// is set to InProc in the Web.config file. If session mode
is set to StateServer
// or SQLServer, the event is not raised.

}

</script>

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Aastha Patel     Answered On: Apr 03

Problem solved. I had to add reference to the following:

<%@ Import Namespace ="Microsoft.SharePoint" %>
<%@ Import Namespace ="Microsoft.SharePoint.WebControls" %>


This code  allows me to store the user's SID in a cookie, which I then
use as a parameter to a dataview web  part. Very nice.

 
Didn't find what you were looking for? Find more on Global.asax HELP Or get search suggestion and latest updates.




Tagged: