|
Hmmm, looks like it could be but theres nothing too complicated about it and theres no shared resources
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
Any help on this error??
This happens when I run the server with ID_A and try to run the client with ID_B .. this is an attempt to try impersonation
System.TypeInitializationException was unhandled
Message="The type initializer for 'System.Runtime.Remoting.Identity' threw an exception."
Source="mscorlib"
TypeName="System.Runtime.Remoting.Identity"
StackTrace:
Server stack trace:
at System.Runtime.Remoting.Identity.RemoveAppNameOrAppGuidIfNecessary(String uri)
at System.Runtime.Remoting.IdentityHolder.MakeURIKey(String uri)
at System.Runtime.Remoting.IdentityHolder.ResolveIdentity(String URI)
at System.Runtime.Remoting.RemotingServices.GetServerTypeForUri(String URI)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.Object.FieldGetter(String typeName, String fieldName, Object& val)
at ns_application.ns_client.cls_client.Main(String[] args) in D:\Vishwjeet\Study\Remoting_tcp\ConsoleApplication2\client.cs:line 64
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Security.Cryptography.CryptographicException
Message="Unknown error \"-2146893801\"."
Source="mscorlib"
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.Utils._AcquireCSP(CspParameters param, SafeProvHandle& hProv)
at System.Security.Cryptography.Utils.AcquireProvHandle(CspParameters parameters)
at System.Security.Cryptography.Utils.get_StaticProvHandle()
at System.Security.Cryptography.RNGCryptoServiceProvider..ctor(CspParameters cspParams)
at System.Runtime.Remoting.Identity..cctor()
InnerException:
|
|
|
|
|
Are you using System.Diagonistic.Process classes to implement impersonation?
Have you placed this in your web.config
<identity impersonate="true"<br />
userName="domain\user" <br />
password="password" />
This might help u...
http://support.microsoft.com/kb/306158[^]
I think the actual problem is CryptographicException when running impersonation.
It is very hard to find the actual problem from this.
|
|
|
|
|
hmmm .. actaully this is happening while im trying remoting ..
i can give u the code .. if u wanna see ..
i am not able to find any message board for remoting .. so was trying my luck out here
|
|
|
|
|
yes why not.. Let me see your code.
Is it happening when you are connecting to a computer in LAN.. Is the domain configured correctly.. ?
Can you connect the remote machine in lan manually?
|
|
|
|
|
I am trying impersonation in remoting ..
The program runs fine when i turn off impersonation. I am running client and server both on the same machine(VISTA).
I have created the user account on the machine .. and it runs fine when i use secure channel and turn impersonation off..
I have also checked that when impersonation is off and using secure channel .. it allows only the users that i have created to logon .. otherwise it gives authentication failure.
Following is the code :
Server:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
using System.Threading;
using System.Security.Principal;
namespace ns_application
{
namespace ns_server
{
public class cls_server
{
static void Main(string[] args)
{
//TcpChannel channel = new TcpChannel(8080);
IDictionary props = (IDictionary) new Hashtable();
IPrincipal threadPrincipal;
props.Add("port", "8080");
props.Add("secure", "true");
props.Add("impersonate", "true");
props.Add("protectionLevel", "EncryptAndSign");
//props.Add("username", "Vishwjeet");
//props.Add("password", "pwd");
//props.Add("authorizationModule", "AuthorizeUser");
//BinaryClientFormatterSinkProvider cp = new BinaryClientFormatterSinkProvider();
//BinaryServerFormatterSinkProvider sp = new BinaryServerFormatterSinkProvider();
IChannel chan = new TcpChannel(props,null,null);
ChannelServices.RegisterChannel(chan,true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ns_registeruser.cls_registeruser), "ApplicationMain", WellKnownObjectMode.Singleton);
threadPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(threadPrincipal.Identity.Name);
Console.WriteLine(threadPrincipal.Identity.IsAuthenticated);
Console.WriteLine(threadPrincipal.Identity.AuthenticationType); Console.WriteLine("Server Started .. ");
Console.ReadLine();
}
}
}
}
Methods :
using System;
using System.Runtime.Serialization;
using System.Reflection;
using System.Data;
using System.Threading;
using System.Security.Principal;
namespace ns_application
{
namespace ns_registeruser
{
//[Serializable]
public class cls_whereitruns:MarshalByRefObject
{
private int _IDNo;
public int IDNo
{
get
{
return _IDNo;
}
set
{
_IDNo = value;
}
}
public int FutureofID()
{
IDNo = IDNo * 5;
Console.WriteLine("Calculated future of ID : {0} :::: {1} :::: {2}", IDNo,this.ToString(),AppDomain.CurrentDomain.FriendlyName);
return(IDNo);
}
public cls_whereitruns(int IDNo)
{
this.IDNo = IDNo;
Console.WriteLine("Created ID : {0} :::: {1} :::: {2}", IDNo, this.ToString(), AppDomain.CurrentDomain.FriendlyName);
}
public DataTable RMS_DIV_Data()
{
//OleDbDataAdapter dataAdapter = new TempDataSet.
TempDataSetTableAdapters.DIV60 da = new ns_application.TempDataSetTableAdapters.DIV60();
TempDataSet.__TKOCLIENT_DIV160DataTable internalTable = new TempDataSet.__TKOCLIENT_DIV160DataTable();
da.Fill(internalTable);
Console.WriteLine("Methods Connection String :: " + System.Configuration.ConfigurationManager.ConnectionStrings["ns_application.Properties.Settings.RetentionManagementSystemConnectionString"]);
Console.WriteLine(internalTable[0][0]);
return internalTable;
}
}
//public class cls_registeruser
public class cls_registeruser : MarshalByRefObject
{
public cls_whereitruns _obj = new cls_whereitruns(5);
private string _username;
public string username
{
get { return _username; }
}
public cls_registeruser()
{
_username = "Blank";
IPrincipal threadPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(threadPrincipal.Identity.Name);
Console.WriteLine(threadPrincipal.Identity.IsAuthenticated);
Console.WriteLine(threadPrincipal.Identity.AuthenticationType);
Console.WriteLine("Registered User " + username);
}
public cls_registeruser(string username)
{
_username = username;
Console.WriteLine("Registered User " + username);
}
~cls_registeruser()
{
Console.WriteLine("Destructor called");
}
}
}
}
Client:
#define VISTA
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
namespace ns_application
{
namespace ns_client
{
public class cls_client
{
static void Main(string[] args)
{
IChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel,true);
//try
//{
#if VISTA
ns_registeruser.cls_registeruser user_obj = (ns_registeruser.cls_registeruser)Activator.GetObject(typeof(ns_registeruser.cls_registeruser), "tcp://kk-pc:8080/ApplicationMain");
#else
ns_registeruser.cls_registeruser user_obj = (ns_registeruser.cls_registeruser)Activator.GetObject(typeof(ns_registeruser.cls_registeruser), "tcp://everest:8080/ApplicationMain");
#endif
IDictionary props = ChannelServices.GetChannelSinkProperties(user_obj);
//props["domain"] = "WORKGROUP11";
#if VISTA
props["tokenImpersonationLevel"] = "identification";
props["username"] = "Vishwjeet";
props["password"] = "pwd";
props["secure"] = "true";
props["protectionLevel"] = "EncryptAndSign";
Console.WriteLine(props["username"]);
#else
props["username"] = "something";
Console.WriteLine(props["username"]);
props["password"] = "hello";
#endif
Console.WriteLine("Till 1");
Console.WriteLine(user_obj._obj.FutureofID());
Console.WriteLine("Till 2");
Console.WriteLine(user_obj._obj.FutureofID());
user_obj._obj.IDNo = 35;
//Console.WriteLine("Client Connection String :: " + System.Configuration.ConfigurationManager.ConnectionStrings["ns_application.Properties.Settings.RetentionManagementSystemConnectionString"]);
Console.WriteLine(user_obj._obj.FutureofID());
Console.WriteLine(user_obj._obj.IDNo);
//Console.WriteLine(user_obj._obj.RMS_DIV_Data());
Console.WriteLine("Client Object Created for user . ." + user_obj.username);
//}
//catch (Exception e)
//{
// Console.WriteLine(e.ToString());
//}
Console.ReadLine();
}
}
}
}
|
|
|
|
|
I have login page and a main page in the asp.net application.In web.config, session Timeout value is set as 5 mins.
My requirements are as below
1.If the main page is idle for 5 mins, the session will expire and the same page will be retained. If the user tries to do some action then it has to redirect to loginpage.
bebuggiung steps
1.comes to session end event in global.asax and the retain the main page
2.comes to session start event in global.asax after the user tries to do some action.
3.check the condition and redirects to login page
2.If the session ends at the time of some action is going in the main page(eg executing a stored procedure for a long time ) then the session has to continue upto the action gets finished.Once it is completed session timeout value has to reset as original value (5 mins)
bebuggiung steps
1. Comes to session end event and assigns the session timeout value to retain the running process in the main page.
I have used the following code to do the above requirements.It is working fine in IIS V5.1 and not working in IIs 6.0 in win 2003 server
Web.config
sessionState timeout="5" mode ="InProc" cookieless ="false"
Global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["Button"] = "Started";
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
HttpContext context = HttpContext.Current;
HttpCookieCollection cookies = context.Request.Cookies;
if (cookies["starttime"] == null)
{
HttpCookie cookie = new HttpCookie("starttime", DateTime.Now.ToString());
cookie.Path = "/";
context.Response.Cookies.Add(cookie);
cookie.HttpOnly = true;
Application["Button"] = "Started";
}
else
{
if (Application["Button"] == "NotClicked" || Application["Button"] == "Error")
{
context.Response.Redirect("~/Logon.aspx");
}
}
}
void Session_End(object sender, EventArgs e)
{
if (Application["Button"] == "Clicked")
{
Session.Timeout = 60;
}
else
{
Application["Button"] = "NotClicked";
}
}
}
Main Page Load
Application["Button"] = "NotClicked";
Main Page Button Click (calling sp in this button)
Application["Button"] = "Clicked";
Please any one help me out to do the same in IIS 6.0. I have tried with worker process idle time also in application pool.
What is the difference in IIS 6.0 with IIS 5.1 using the above code with cookies? Please any one reply me as soon as possible. its very urgent....
Prasanna
|
|
|
|
|
I need to know the user IP to give the right limit to access my website,
how to detect the user IP?
and moreover, how to know which country is the user from?
thanks!
|
|
|
|
|
|
This is a good article.
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
Hi you are in right direction and it is correct. It alwasy gives IP: 127.0.0.1 because you are requesting from your local machine.
When you will acces you web application via different machine then it will give the correct IP.
Anyway your code is correct.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
thanks, I see,
but do you know
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
gives also IP? or sth else?
thank you again!!
your article is great!!
|
|
|
|
|
This will give Host IP where your application is deployed. But you are looking for visitor/Client IP.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
really? if so, I am confused by this code.
thanks again!
|
|
|
|
|
Yes
Now your next job is to find the country name.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Seraph_summer wrote: your article is great!!
At least the Database provided in the article is the most important part of it. Its a great one indeed.
|
|
|
|
|
Client IP could be found from
ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR");
if(ip==string.Empty)
{
ip=Request.ServerVariables("REMOTE_ADDR");
}
|
|
|
|
|
Hi, thanks!
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
|
|
If the user is behind a proxy then REMOTE_ADDR will be the proxy IP address and HTTP_X_FORWARDED_FOR will be the client IP address. HTTP_X_FORWARDED_FOR can consist of multiple comma separated IP addresses for each proxy the request passes through. Generally, client IP is the first of them.
Finally, you can rely on the above methods only for Transparent proxies. There is no way to trace the actual IP in case of Anonymous or Distorting proxies.
One more good tool for finding country from an IP is this one[^] on codeplex.
|
|
|
|
|
Please Help ,I have 3 day for my presentation in university just
I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
I use VS2008(C#) without service pack.PLZ Hlp
|
|
|
|
|
morteza451 wrote: I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
Can you please give us the code block ?
If you want to know more about these controls, please read this
ASP.NET Login Controls Overview[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello everyone,
I am using Windows Server 2003 + VSTS 2008 + .Net 3.5 + C# + ASP.Net + IIS 6.0. I host some files (wmv video file and html file) on the web server, I want to know whether there are any easy to use authentication approach to let user input username and password before they can access (I want to prevent anonymous access)? Since the web site has also aspx ASP.Net page, and I want to use an unified authentication solution for wmv, html and aspx page. If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
Any ideas?
thanks in advance,
George
|
|
|
|