httpcontext

Access HttpContext.Current from different threads

痴心易碎 提交于 2019-11-26 18:38:51
I have a C# ASP.NET application which starts about 25 different threads running some methods in a class called SiteCrawler.cs. In HttpContext.Current.Session I want to save the result of the search made by the user and present it to the user when all the threads are finished running. My problem is that the HttpContext.Current object is null in the spawned threads because it doesn't exist there. What other options do I have to save user/session specific data without using session because of the limitations when the application is multithreaded? I have tried to search around every inch of

Correct way to use HttpContext.Current.User with async await

…衆ロ難τιáo~ 提交于 2019-11-26 18:12:41
问题 I am working with async actions and use the HttpContext.Current.User like this public class UserService : IUserService { public ILocPrincipal Current { get { return HttpContext.Current.User as ILocPrincipal; } } } public class ChannelService : IDisposable { // In the service layer public ChannelService() : this(new Entities.LocDbContext(), new UserService()) { } public ChannelService(Entities.LocDbContext locDbContext, IUserService userService) { this.LocDbContext = locDbContext; this

Writing to ZipArchive using the HttpContext OutputStream

依然范特西╮ 提交于 2019-11-26 13:56:24
问题 I've been trying to get the "new" ZipArchive included in .NET 4.5 ( System.IO.Compression.ZipArchive ) to work in a ASP.NET site. But it seems like it doesn't like writing to the stream of HttpContext.Response.OutputStream . My following code example will throw System.NotSupportedException: Specified method is not supported as soon as a write is attempted on the stream. The CanWrite property on the stream returns true. If I exchange the OutputStream with a filestream, pointing to a local

HttpSelfHostServer and HttpContext.Current

荒凉一梦 提交于 2019-11-26 13:18:38
问题 I'm working on a self-hosted ASP.NET web api-application. Everything works fine, but now I'm struggling with HttpContext : I need to save session-informations from the client. But HttpContext.Current is always null. So it's obvious that my HttpSelfHostServer don't work with the static HttpContext-Class. The thing I don't understand is: why..? And I can't figure out a way to tell neither HtttpSelfHostServer nor HttpSelfHostConfiguration to work with HttpContext . Here's what I'm doing:

HttpContext.Current.User.Identity.Name is always string.Empty

牧云@^-^@ 提交于 2019-11-26 13:09:12
问题 Hi I use a custom MembershipProvider. I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty. if (Membership.ValidateUser(tbUsername.Text, tbPassword.Text)) { FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //\"\" FormsAuthentication.RedirectFromLoginPage(tbUsername.Text, cbRememberMe.Checked); } Am

Get current System.Web.UI.Page from HttpContext?

寵の児 提交于 2019-11-26 12:38:27
问题 This is actually a two part question. First,does the HttpContext.Current correspond to the current System.UI.Page object? And the second question, which is probably related to the first, is why can\'t I use the following to see if the current page implements an interface: private IWebBase FindWebBase() { if (HttpContext.Current as IWebBase != null) { return (IWebBase)HttpContext.Current.; } throw new NotImplementedException(\"Crawling for IWebBase not implemented yet\"); } The general context

HttpContext.Current.User.Identity.Name is Empty

风格不统一 提交于 2019-11-26 11:06:28
问题 I have a Silverlight application (using MVC) and when i\'m building in visual studio, using Visual Studio Development center, there\'s no problem, the HttpContext.Current.User.Identity.Name has a Value But when i\'m using the same project with IIS 7.5 (i\'m using Windows 7), HttpContext.Current.User.Identity.Name stays empty Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what\'s wrong in IIS? 回答1: I struggled with this

How to get working path of a wcf application?

允我心安 提交于 2019-11-26 09:24:26
问题 I want to get the working folder of a WCF application. How can I get it? If I try HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) I get a null reference exception (the Http.Current object is null). What I meant with the working folder was the folder where my WCF service is running. If I set aspNetCompatibilityEnabled=\"true\" , I get this error: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session

Why is HttpContext.Current null?

我的未来我决定 提交于 2019-11-26 08:27:10
问题 I have a value that I use in all the application; I set this in application_start void Application_Start(object sender, EventArgs e) { Dictionary<int, IList<string>> Panels = new Dictionary<int, IList<string>>(); List<clsPanelSetting> setting = clsPanelSettingFactory.GetAll(); foreach (clsPanelSetting panel in setting) { Panels.Add(panel.AdminId, new List<string>() { panel.Phone,panel.UserName,panel.Password}); } Application[\"Setting\"] = Panels; SmsSchedule we = new SmsSchedule(); we.Run();

System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET

吃可爱长大的小学妹 提交于 2019-11-26 07:46:33
问题 What is the difference between System.Web.HttpContext.Current.User.Identity.Name and System.Environment.UserName in the context of a ASP.Net Web Application Project? Here\'s the code of what I\'m trying to do: Database myDB = DatabaseFactory.CreateDatabase(); bool IsAuthUser = myDB.ExecuteScalar(\"procIsAuthorizedUser\", System.Environment.UserName); If they are functionally identical, which is better in terms of performance? This is a C# 4.0/ASP.Net web application which will see moderate