httpcontext

Castle.Windsor and HttpContextWrapper

早过忘川 提交于 2019-12-30 12:17:49
问题 HttpContextWrapper and HttpContextBase, as explained here, were introduced to make HttpContext more mockable/testable. I'm trying to use it with S#arp Architecture, and hitting some problems. My MVC Controllers are set up to accept an HttpContextBase argument in the constructor, and during Application_Start, HttpContextBase is registered with Castle.Windor as follows: container.Register(Component.For<HttpContextBase>().UsingFactoryMethod( () => new HttpContextWrapper(HttpContext.Current)));

HTTPContext.Current.User.Identity.Name not working inside a control?

て烟熏妆下的殇ゞ 提交于 2019-12-25 17:01:25
问题 I have a label and I want to set text of this label to HTTPContext.Current.User.Identity.Name So I wrote Text = '<%=HTTPContext.Current.User.Identity.Name %>' but it doesn't work, however when I wrote this outside of the lable for example: <h2> <%=HTTPContext.Current.User.Identity.Name %> </h2> it works. 回答1: <asp:Label ID="lbUserName" runat="server" Text='<%# HttpContext.Current.User.Identity.Name %>' /> in Page_Load if (!Page.IsPostBack ) { lbUserName.DataBind(); } 回答2: use label like this

In MVC5 how can I create user records in code?

╄→гoц情女王★ 提交于 2019-12-25 15:55:38
问题 VS2013, MVC5, VB The MVC5 template works well to create new users from the Register View while the application is running. But if I want to create users in code, how do I do that? The following is naïve code, but demonstrates what doesn't work: Dim user = New ApplicationUser() With {.UserName = "name@live.com", .Email = "name@live.com"} Dim acct As New AccountController acct.UserManager.CreateAsync(user, "Temp1.11") This doesn't work because there is no HttpContext for UserManager. There's a

Open a file when it downloads with HttpContext

旧城冷巷雨未停 提交于 2019-12-25 08:02:49
问题 I have a handler that I call when a link gets clicked. This handler gets the file contents from the DB and writes the contents to context.Response. I'd like to open this file as well along with it getting downloaded. Is this possible? 回答1: You have no control over browser's behavior. It will either open in browser OR display open/save dialog. You may try to render custom page with HTML view of the file and automatically trigger second download from that HTML page to force open/save dialog.

Why is HttpContext.User null after AuthenticateRequest is complete

 ̄綄美尐妖づ 提交于 2019-12-25 02:29:27
问题 The standard way to check if the current request is authenticated is with HttpContext.User.Identity.IsAuthenticated . I have just run into a case where the User property is null so I cannot make the check! I found an article describing the IIS request pipeline. I'm at the PostResolveRequestCache stage which is clearly after AuthenticateRequest ! Why would HttpContext.User still be null at that point? 回答1: The FormsAuthenticationModule was not running. I had to manually add it to my web.config

HttpContext.Current null in async after await calls

蹲街弑〆低调 提交于 2019-12-24 17:09:02
问题 HttpContext.Current null in async after await calls. Here is my code: if (!string.IsNullOrEmpty(securityGroupName)) { // To remove the domain name from the security group name. string securityGroupDisplayName = securityGroupName.Split('\\')[1]; string serviceSecurityGroupId = await this.graphApiClient.GetGroupIdAsync(securityGroupDisplayName).ConfigureAwait(false); if (!string.IsNullOrEmpty(serviceSecurityGroupId)) { Task securityGroupRoleAddTask = this.CheckMembershipAndAddRole

Storing context object in Request object, is it disposed of?

半腔热情 提交于 2019-12-24 09:49:42
问题 I am writing a MVC3 application, using NInject DI and repository pattern. Ninject is set up so that the repositories have a per-request lifetime. I am putting the context object into the Http Request object, using the following code: public static MessengerEntities GetContext() { if (!HttpContext.Current.Items.Contains("_db_context")) { HttpContext.Current.Items.Add("_db_context", new MessengerEntities()); } return (MessengerEntities)HttpContext.Current.Items["_db_context"]; } Then each

access httpcontext.session in GrantResourceOwnerCredentials

◇◆丶佛笑我妖孽 提交于 2019-12-24 09:48:06
问题 I need to get HttpContext.Session in GrantResourceOwnerCredentials method. However I get null when I try to access Httpcontext.Session . Below is my code: public void ConfigureAuth(IAppBuilder app) { PublicClientId = "self"; OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider( PublicClientId, DependencyResolver.Current.GetService<ApplicationUserManager>(), HttpContext.Current), //AuthorizeEndpointPath = new

MVC Mocking (Moq) - HttpContext.Current.Server.MapPath

筅森魡賤 提交于 2019-12-24 08:39:31
问题 I have a method I am attempting to Unit Test which makes use of HttpContext.Current.Server.MapPath as well as File.ReadAllLines as follows: public List<ProductItem> GetAllProductsFromCSV() { var productFilePath = HttpContext.Current.Server.MapPath(@"~/CSV/products.csv"); String[] csvData = File.ReadAllLines(productFilePath); List<ProductItem> result = new List<ProductItem>(); foreach (string csvrow in csvData) { var fields = csvrow.Split(','); ProductItem prod = new ProductItem() { ID =

How can I keep track of a shopping cart across multiple projects?

自作多情 提交于 2019-12-24 06:07:29
问题 First some background, we are creating a new "eGov" application. Eventually, a citizen can request permits and pay for licenses along with pay their utility bills and parking tickets online. Our vision has a shopping cart so a person can pay for multiple items in one transaction. To keep things organized better, we are going to break each section into a different project. This also allows me to work on one project while the other developer works another. The person making a payment could be a