get currently logged in username asp.net without c# - asp.net

I'm working on a school project (so security isn't an issue) that requires me to get the name of the currently logged in user (to use as an argument for an SQL query for a datagrid)
Since the SQL query for the datagrid binding is stored in the aspx file, I can't use User.Identity.Name.ToString() like I would if this were in my c# file.
I am using the Microsoft authentication system that comes pre-built in visual studio asp.net webforms

You can use filter parameter of SQL Data-source.
Try using plain parameter (asp:Parameter). Yet another alternative is using SessionParameter or writing your own custom parameter (see this SO question: How to utilize ASP.NET current user name in SqlParameter without code-behind)

You should be able to use the following in the ASPX file:
<%=HttpContext.Current.User.Identity.Name %>
You obviously won't need the tags if you are plugging it into an existing code block...

Related

ASP.NET MVC with User Defined Type

I try to create simple ASP.NET MVC5 app where I can access to my table. The table has user defined type inside.
I followed this tutorial:
http://www.asp.net/mvc/overview/older-versions-1/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs
Unfortunately, when I use Entity Data Model and try to generate model from database, my UDT field is ignored. I've got an warning:
The data type 'Pesel' is currently not supported for the target Entity Framework version; the column 'x' in the table 'y' was excluded.
So my question is, how can I add my UDT to entity model?
I've tried to manually create a model and then use Entity Framework to generate controller and views. Again, UDT fields are ignored.
Thanks for help!
I've personally not used User Defined Types, but I'm sure you have a good reason for it. After reading your question, I decided to learn more about UDT's and try and find an answer for you. From what I've read, you should be able to do it as long as you reference the assembly for the definition in your project. Otherwise, your project will have no idea what the data type is or how to use it.
Here is some text from the "Professional C# 4 and .Net 4" book:
Using UDTs from Client - side Code
The assembly of the UDT must be referenced to use the UDT from client
- side code. Then it can be used like any other type on the client.
Because the assembly containing the UDTs is used both from the client
and from the SQL Server, it is a good idea to put UDTs in a separate
assembly from the other SQL Server extensions such as stored
procedures and functions.

COM visible .NET class cannot get System.Web.HttpContext.Current when used in classic asp

My company would like to update legacy visual basic 6/classic asp code. We do not have access to a visual basic 6 compiler, so it seemed like a good idea to use Visual Studio 10 and recompile the visual basic 6 code as a VB.NET class. With some minor modifications everything compiled and we registered it as a com object to be called from classic asp.
Now we are trying to access global variables from the asp server. After an extensive search on Google, the only way mentioned was to use System.Web.HttpContext.Current or System.Web.HttpContext.Current.Application . However, this doesn't appear to work.
Here is the code leading up to error. We have imported System and System.Web.
Public Function DoSomethingUseful() As String
Dim objCurrent As System.Web.HttpContext
DoSomethingUseful = Nothing
objCurrent = System.Web.HttpContext.Current
If objCurrent Is Nothing Then
Throw New Exception("No Context.") '<--- THIS EXCEPTION IS THROWN
End If
The problem is we can't get a current instance of the http context and the exception is thrown. Every example I've seem shows that the line objCurrent = System.Web.HttpContext.Current should work but it doesn't. Perhaps it's because we are not using ASP.NET? If not then why isn't it working?
Yes, it is because you're not using ASP.NET.
Despite the similar sounding names, and to a certain degree similar design choices, there is no relationship whatsoever between ASP.NET anything and "Classic" ASP anything. They are completely independent environments.
To access directly the ASP context objects (not the similarly-named ASP.NET context objects which in your application don't even exist), your object must be a registered COM+ object, so:
Your class must inherit from System.EnterpriseServices.ServicedComponent *
On Windows 7/2008 and up, you must enable the "Allow IIS Intrinsic properties" from Component Services, just like you would have to in VB6 (open \Component Services\My Computer\COM+ Applications\YourComPlusApp\Components; select all the objects that need the ASP objects; right-click; click on Properties; go to the Advanced tab).
You can then retrieve the ASP objects (Application, Server, Request, Response, Session) from the COM+ ObjectContext.
Your code would look something like this:
objCurrent = System.EnterpriseServices.ContextUtil.GetNamedProperty("Application")
There are also attributes that you can add to your class to simplify the deployment of the code, but that's a bit outside the scope of this question.
For your reference:
ASP Built-in Objects
ContextUtil.GetNamedProperty Method
* I don't remember 100% if this is a hard requirement. It might actually depend on what the object is actually doing with COM+.

aspCode runner generates which syntax of CODE?

i'm using ASP RUNNER software to generate auto code, it generates this code
Function employeeRecord_Snippet1()
Response.Write "Your message"
End Function ' employeeRecord_Snippet1
now i don't understand that is it ASP.net code or ASP code ?
From the product homepage
"ASPRunnerPro creates professionally looking classic ASP applications enabling users to search, edit, delete and add data to the Oracle, SQL Server, MS Access, DB2, or MySQL databases."
http://xlinesoft.com/asprunnerpro/

simple webservice code?

i write a simple webservice code in asp.net when i build the service and run the service it is working fine. when i try to access the webservice it is giving some problem , problem means i am not getting that method (webservice method). After completing writing the webserivce i take a asp.net page (.aspx) and in solution explorer i add a webservices and it is added successfully. but when i adding namespace it is not getting the service name ( i not able to add the namespace of websercice
I am not exactly sure what could be the problem but you should only need to do the following to use the web service:
// Look at what you named your web reference, in my example it is
// called MyWebService. Check your solution explorer for the actual name.
// This is the alias you should be using.
MyWebService.YourWebServiceName ws = new MyWebService.YourWebServiceName();
var result = ws.MyMethod(someparameter);

Tilde not resolving in HyperLinkColumn in ASP.NET 2.0

I have an ASP.NET application originally deployed to a .Net 1.1 Framework on Windows 2000 server which i'm now using on a Windows 2008 Server using 2.0.50727. We use the tilde (~) to resolve to an absolute path in many areas of the application and it works for things like asp:hyperlink controls (with run-at server tags), but for our bound datagrid controls which are using HyperLinkColumns to create links based on ID values returned from our database, the tilde is getting written to the page.
This code:
HyperLinkColumn oLink = new HyperLinkColumn();
oLink.DataNavigateUrlField = "IdField";
oLink.DataNavigateUrlFormatString = "~/Here{0}.aspx";
is dumping this to the page:
<a href="~/Here171201.aspx">
What changed between versions of IIS or .NET Framework could be causing this functionality to no longer work? The Tilde was definitely resolving in 1.1 - I have the exact same code deployed on a dozen 1.1 Framework servers in our organization. Unfortunately, the class that sets the DataNavigateUrlFormatString doesn't have access to the Page, so I'll have to do some kludging to insert the Page.ResolveUrl work around...
I'm not aware of anything changing, but I don't use HyperLinkColumns (I prefer the control which the Template column provides) so I've not looked for any changes .
One possibility as a proverbial band aid is to change this line:
oLink.DataNavigateUrlFormatString = "~/Here{0}.aspx";
to this:
oLink.DataNavigateUrlFormatString = Page.ResolveUrl("~/Here{0}.aspx");
If memory serves there was some issues when going to Master Pages and using the '~' from User Controls, but it's been a while since I read anything like that.
I don't think that the HyperlinkColumn of a Datagrid automatically resolves the URL into an absolute path. IIRC, the DataNavigateUrlFormatString property internally calls String.Format() only on the supplied format. Are you sure this worked correctly on .NET 1.1? IIRC, .NET 1.1 did not have tilde-based automatic URL resolution.
In my opinion, you should use the solution presented by Stephen (call Page.ResolveUrl manually.)

Resources