What is the alternate way for "Request" class/object in .NET core? - request

I am migrating an existing ASP.NET Web API 2 project to ASP.NET Core. While migrating I am unable to find this.Request object. Can anyone help me solve out this issue?

This question was asked here, but since ASP.NET Core was still probably in an RC state then, I figured I'd answer here instead of referring to there because there is some stuff that's obsolete or completely gone from the official release.
Assuming your controller class inherits from Controller (or more specifically, ControllerBase) then it does have a this.Request property as you can see here and here. As Pawel noted, you can also access it from the this.HttpContext property.
The request's URL is broken up into several properties on HttpRequest. You can access the URL in a friendlier API by adding using Microsoft.AspNetCore.Http.Extensions; which gets you access to the following extension methods:
GetDisplayUrl()
GetEncodedUrl()
As far as the query string, HttpRequest provides QueryString and Query properties for you to interact with.
Side note: I just created an app from scratch targeting ASP.NET Core on .NET Core for the first time on this laptop, and it took a while for the Intellisense to work for the Request property, so I'm wondering if that could have been your issue.

You need to override your class like this to get this.Request
public partial class _Default : System.Web.UI.Page

Related

I need to implement Asp.net Web API 2 and consume it by Sencha Ext JS

I want to implement a web-based API (using ASP.NET Web API 2) and consume it by the client Side library (Sencha Ext JS).
My application should include
A simple user registration form.
A login page for admin.
CRUD operations for users' submissions.
Notes:
I do not want to include any backend code (i.e C#) in the we application, I want to implement it using the HTML/Javascript only, that is Ext JS.
I want the Web API to be RESTful.
I want to protect admin pages.
I want to use the SQL Server to store users' submissions.
All of that requirements should be implemented using the ASP.net Web API 2 and Ext JS only.
So far, I did initial search and I got a lot of learning for either the ASP.net API 2 or the Ext JS. But I couldn't have a guide that help me to fulfill the above requirements or help me to have both technologies work together.
Pleas help me on either way.
Or generally, can you help me get started work in combining both: Asp.net Web API 2 and any client side that consumes it, such as Sencha Ext JS or any other client side. It is not necessarily to be Ext JS.
Thank you so much.
Thanks to StackOverflow.com
If it were me, I'd use the DirectAPI for asp.net https://github.com/elishnevsky/ext-direct-mvc
You create webapi controllers, just like you normally would. The only difference is the the controllers that need to be used by EXT should inherit from DirectController.
If you follow the directions on that page, you'll end up with a globally available proxy object that matches the name of the controller and the public methods hanging off of the controller become methods of that object.
That is, server side controller MyAwesomeController with method DoSomething() becomes MyAwesome.DoSomething.
If you attribute the method as [NamedArguements] you can create methods such as
DoSomething(int id, int foo)
and pass from javascript as DoSomething({id: 20, foo: 30});
Since it is still just a controller, you can attribute permissions and return json as you would in any other situation.
If you get stuck, use the debugger and spend the time to figure out what's really going on. This all works in 4.x and I've tried it in 5.x and it still works there as well. But I wouldn't jump into 5.x just yet as there are still several bugs that need to be worked out by the sencha team before it is ready for prime time.
ExtJs has a REST proxy for the data. So what you try to do should be possible. The proxy can be configured and be finetuned.
I used the JSON proxy. ExtJs has very powerful filter and sort capabilities, both server and client side. In my experience difficulties arose when filtering and sorting server side. There is only sparse documentation on how the parameters are passed and which configurations have what effects.
Since you also develop the REST api, you can adapt to those details. You just have to do some research.
Here is not the place to ask about guides. For Asp I cannot help you, I never touched it. If you use ExtJs, you are free to choose you backend. For ExtJs, the start is pretty straight forward :
get Sencha cmd and generate a skeleton app.
follow the tutorial
create one file per class definition.
the API docs are great. If you still lack something SO is great too.
what you have to find out by yourself is the exact way parameters are passed to the backend and how to format the response.

Can AngularJS work in Java EE MVC Architecture : JSP->Servlet->EJB3.1->Business Object->DAO

I have a quick question on considering AngularJS (current stable version - 1.3.9) for an upcoming application that we are building on an existing framework. The current framework has a Java EE MVC architecture and here are the current components mentioned in sequential order in which they get invoked:
View - JSPs: This layer gets as response Java Objects and we use jsp:useBean to access its properties and display on screen.
If any modifications are done on the page, it goes through a ControllerServlet i.e a Java file which has code to access the HttpRequest and HttpSession related information. The controller also does a lookup in JNDI to find the name of the bean to invoke based on the HttpRequest parameter name, e.g. PageId
Once the EJBBean lookup is returned, the controller invokes an EJB 3.1 "no-interview" view - These are Stateless Beans annotated with #Stateless
EJBBean classes then invoke BusinessObject classes, we call them "BO" which internally gets referenced by the DAO interface
A DAO implementation class is the one which is responsible for CRUD operations
Our Problems as of now:
The view is tightly coupled to Java Objects that are returned from DAOs and since the response is not converted to JSON, a lot of scriptlet code is used to display their value (I know scriplets are oldskool, but being a legacy solution there is no choice)
jQuery is used to manipulate the DOM before sending it to the controller layer
View is not the official record of whats happening on the screen, unlike AngularJS where I could easily understand
Developers write custom CSS for different browsers manually
Proposed Solution
View shall be designed for the new application using AngularJS
Take advantage of Bootstrap css classes which has readily available CSS which can be combined with AngularJS
Each request goes to ControllerServlet using $http service to ensure we use existing MVC architecture i.e routing every request through Controller
EJB Layer to be RESTFul to return data in JSON Format
Viewport specific css code for responsive web design - i.e same screen should render on multiple devices and platforms
Questions:
Is the proposed solution feasible? What are the downsides?
Is it a good practice to reference EJB Bean classes as RESTFul services?
Do we get access to all the Java EE objects / interfaces using AngularJS? For e.g. HttpRequest, HttpSession, etc.
Will it help in performing better by switching to this architecture?
Question from Management - Why not stick with jQuery! - Probably the hardest of all the questions to convince the management of Angular's benefits
Hope you guys can help throw some suggestions
i'm using spring 4.0.1 , hibernate 4.3.5 ,jackson 1.9.2 , I'm creating a RESTful webservice that returns a data in JSON format and angularjs in front-end which is loosely coupled with back-end.
concerning your questions;
the solution is feasible of course , until now there no downsides
except session management is tricky because Restful ws is stateless
.
it's provide a very elegant feature that you can access all your
functionality via any application web-client-side, desktop or
mobile.
angular app is fully isolated from back-end app you can maintain
requests and session in the server and respond with what you like in
json format to angular
same as 2
i hope it's helpful

wicket/bookmarkable added after wicket migration

Im migrating a wicket webapplication from wicket 1.4 to wicket 6.8.
Im having some problems with the bookmarkable/non bookmarkable implementation introduced in wicket 1.5.
The application now adds wicket/bookmarkable to "bookmarkable" pages when setresponsepage is called. it does not matter if i provide a class or an instance of a page. My applications keeps adding wicket/bookmarkable.
I dont want to have the wicket/bookmarkable prefix in the url. I have tried to make a new implementation of imappercontext to override these prefixes. But i dont want them at all. Actually i dont bookmarkable pages in my application at all, besides some mounted pages.
Any ideas about how to remove this prefix?
You must mount page to remove wicket/bookmarkable in the url. Override the init method and configure on your WebApplication.
#Override
public void init() {
super.init();
...
mountPage(your_url, YOUR_PAGE.class);
}
I took a look at my code (we somewhat recently updated to Wicket 6.x) and did not notice it before, but I am also getting the 'bookmarkable' string in my url when I call
setResponsePage(SomePage.class);
however, in other places the link is set up as
setResponsePage(new SomePage());
and the 'bookmarkable' string is not included in the URL.
Hope this helps...

Sending abstract class with DomainService WCF service to Silverlight

I was using a simple WCF service with silverlight but I wanted to validate data with annotations and I didn't want to write a whole new layer in silverlight project. So I decided to switch to using a DomainService, created through generating code in the silverlight project.
Now comes the trouble. I have a parent class and about 10 derived classes. Through WCF, I was able to just use the base class. Now I am trying to use a DomainService with the base class decorated with the KnownType attribute. The problem is now those attributes get replicated in silverlight client and a compilation error is thrown. Anybody know how to use DomainService with inheritance? I want to deliver only the information from the base class.
I don't completely follow what your problem is, but this is a great tutorial on how to use Domain Services in Silverlight, and the example includes an abstract base class for all entities, similar to what I think you're doing.

Ria Service Generated Code Not Accessible in Silverlight Code

I have the following Ria Service define:
namespace SilverlightTest.Web
{
[EnableClientAccess()]
public class ContactService : LinqToEntitiesDomainService<AdventureWorksEntities>
{
public IQueryable<Contact> GetContactSearch(string lastName)
{
ContactRepository rep = new ContactRepository();
return rep.SearchByLastName(lastName);
}
}
}
When I compile the solution, my SilverlightTest project does create the SilverlightTest.Web.g.cs file and the appropriate Context objects are created when I look at it. However, when I attempt to import the SilverlightTest.Web namespace to access the Data Context class for the above service, it says it cannot find the Web namespace.
The only difference I can see between what I'm doing and many examples that are out there on the web is that my AdventureWorksEntities data context is located in a separate business object dll. I tried to query the context directly instead of using the Repository Pattern I'm attempting to do and it also isn't work working.
Any ideas? Is it possible to have Ria Services access a separate DLL handling data access or does it HAVE to be in the same project?
I've been able to put the Ria service in a separate project before, although I do remember having issues. Not sure exactly what it was, but I would check two things: your references and your web.config (in the hosting website). When you add a ria service to a web project it does some things behind the scenes that wire everything up correctly.
Could try adding a service to your web project temporarily and see what it adds.
It seems that Resharper does not recognize the .gs files and their name spaces. If you disable R# or just code without intelisense it works.

Resources