httpcontext

Play framework 2.0: Store values in Http.Context

喜欢而已 提交于 2019-12-13 13:31:18
问题 I'm trying to implement "request based" sessions in scalaquery in the play framework. I create a session using scalaquery and attempt to store it in the current http context, as follows: def withTransaction[A](bp: BodyParser[A])(f: Request[A] => Result): Action[A] = { Action(bp) { request => val context = Http.Context.current() val session = createSession() session.conn.setAutoCommit(false) context.args.put("scalaquery.session", session) try { val result = f(request) session.conn.commit()

POST Request not supported by Google Server

北战南征 提交于 2019-12-13 05:32:25
问题 I am getting following error while posting request from my server to google.com: Warning: file_get_contents(http://accounts.google.com): failed to open stream: HTTP request failed! HTTP/1.0 405 Method Not Allowed in C:\...\index.php on line 23 My code is following: $postdata = http_build_query( array( 'code' => '####', 'client_id' => '####', 'client_secret' => '####', 'grant_type' => 'authorization_code' ) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:

How do I get the website URL or access the HttpContext from a IHostedService in ASP.NET Core?

大兔子大兔子 提交于 2019-12-13 03:18:43
问题 In our MultiTenant ASP.NET Core 2.2 app, we determine the tenant from the URI. How can get the website URL from an IHostedService? The HttpContext is always null. The IHttpContextAccessor.HttpContext IS ALWAYS NULL public MyHostedService(ILogger<TurnTimeTask> logger, IHttpContextAccessor httpContextAccessor) { _logger = logger; _httpContextAccessor = httpContextAccessor; } Even running the IHostedService in Scope also returns NULL for the httpContextAccessor.HttpContext i.e. Injecting it

Getting JavaScript runtime error: irrationalPath, what does it mean?

守給你的承諾、 提交于 2019-12-12 18:43:12
问题 In my MasterPage i'm using the following script <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.3"></script> And in my application, i have this peace of JavaScript code document.getElementById(menu_number).src = "<%=HttpContext.Current.Request.ApplicationPath%>/UI/Common/Images/down-arrow.gif"; I also have the Application_AcquireRequestState method below public void Application_AcquireRequestState(object sender, EventArgs e) { // Get http context from

MVC3 generic handler (.ashx) for Images resizing (Need clean URL)

邮差的信 提交于 2019-12-12 17:29:57
问题 I have a generic handler (.ashx) in asp.net mvc3 web application. I use it to resize and cache images. but my Url is not clean (http://www.example.com/Thumb.ashx?img=someimage.jpg) I want to make it clean like http://www.example.com/Thumb/someimage.jpg how can I do it? Can I maproute in global.asax, it yes then how? or should I use IIS 7 URL rewrite? I appreciate any help, Thanks 回答1: After few hours of research I have done it using class (RouteHandler.cs) http handler but not with .ashx

adding header to http response in an action inside a controller in asp.net/mvc

为君一笑 提交于 2019-12-12 08:23:55
问题 I am streaming data from server to client for download using filestream.write . In that case what is happening is that I am able to download the file but it does not appear as download in my browser. Neither the pop-up for "Save As" appears not "Download Bar" appears in Downloads section. From looking around, I guess I need to include "something" in the response header to tell the browser that there is an attachment with this response. Also I want to set the cookie. To accomplish this, this

How to access HttpContext inside a unit test in ASP.NET 5 / MVC 6

£可爱£侵袭症+ 提交于 2019-12-12 07:09:42
问题 Lets say I am setting a value on the http context in my middleware. For example HttpContext.User. How can test the http context in my unit test. Here is an example of what I am trying to do Middleware public class MyAuthMiddleware { private readonly RequestDelegate _next; public MyAuthMiddleware(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext context) { context.User = SetUser(); await next(context); } } Test [Fact] public async Task UserShouldBeAuthenticated() {

ASP.NET Session is not keeping stored across pages

廉价感情. 提交于 2019-12-12 04:57:42
问题 First, I created a Login page that added a key value pair to the session and verified that on that page the session holds that pair. Next, I attempt to go to another page that looks for that pair in the session and it is not there. I've put the timeout for the session to 15000 so it won't timeout. I currently use a static class to look at the session, HttpContext.Current.Session. Each Page calls this static class to look at the session but every time the session key count = 0 except after I

Current user identity in ObjectContext.SavingChanges

£可爱£侵袭症+ 提交于 2019-12-12 04:38:22
问题 I am using ObjectContext.SavingChanges event to update CreatedDate/UpdatedDate columns based on the object state like this partial void OnContextCreated() { //Extension of the Command Timeout to avoid processing problems. CommandTimeout = 600; //Time in seconds this.SavingChanges += new EventHandler(Entities_SavingChanges); } protected void Entities_SavingChanges(object sender, EventArgs e) { var addedObjects = this.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added);

Mock httpcontext.current.request.files

南楼画角 提交于 2019-12-11 23:14:37
问题 I am implementing nUnit Test case for one of my method called, UploadFile() , some thing like below public void UploadFile(string siteId, string sitePageId) { int fileCount = HttpContext.Current.Request.Files.Count; //Rest of code } so basically i am reading file using HttpContext.Current.Request.Files . From UI it is working fine but when i am implementing nUnit test case for it, i am not able to mock HttpContext.Current.Request.Files . I googled about some of mocking tools but there also i