You people might be think this question is pretty simple but really I am structed here. Could you please give me a proper solution for this
I have a Windows sample like the following in button click event
AuthURI= "http://.......";
**Webbrowser1.Navigate(AuthURI);**
private void **Webbrowser1_DocumentCompleted**(object sender, WebBrowserDocumentCompletedEventArgs **e**)
{
try
{
if (e.Url.ToString().Contains("code="))
{
string[] responseOauth = Regex.Split(e.Url.ToString(), "&");
for (int i = 0; i < responseOauth.Count(); i++)
{
string[] nvPair = Regex.Split(responseOauth[i], "=");
drive.AccessCode = nvPair[1];
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
This is windows application code but now I want to change this application into web application
but I strucked WebBrowserDocumentCompletedEventArgs e how to pass this event like e.Url in my web application
what is replacement for this event I tried in google but exact result I didn't get. Please give me a proper solution for this
Related
I have a block of code, where I have enabled the developer mode, but still the logs are not logging in the App insight.
static void Main(string[] args)
{
{
try
{
int a = 5;
int b = 0;
int c = a / b;
}
catch (Exception ex)
{
CreateLogAI(ex, "code");
}
}
}
public static void CreateLogAI(Exception ex, string CodeBlock)
{
TelemetryClient TeleClient = new TelemetryClient();
TelemetryConfiguration.Active.InstrumentationKey = "XXXX";
try
{
TeleClient.TrackException(ex);
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;
}
catch (Exception exception)
{
throw exception;
}
finally { TeleClient.Flush(); }
}
So I referred number of article. Developer mode & the Flush should work. This is the sample code I have. What I am missing here?
Sleep after Flush(). Thread.Sleep(5000);
I just copy your code, and it works fine and logs can be seen in azure portal.
There are two steps you can use to check if logs are sent to appInsights:
1.After run your code in visual studio, please check the output window, see if this line of text is there, it starts with Application Insights Telemetry:, screenshot as below:
2.If you cannot see the message describe in step 1, please add System.Threading.Thread.Sleep(5000) before the Flush() method in finally{}, then check the output window again.
Here is the test result at my side, please note that it may take a few minutes for the logs to be shown in azure portal:
In an MVC web application I use the SpeechSynthesizer class to speak some text to a .wav file during a function called by a controller action handler that returns a view. The code executes, writes the file, and the action handle returns, but the development server usually, but not always, never comes back with the return page. This is the text-to-speech code:
string threadMessage = null;
bool returnValue = true;
var t = new System.Threading.Thread(() =>
{
try
{
SpeechEngine.SetOutputToWaveFile(wavFilePath);
SpeechEngine.Speak(text);
SpeechEngine.SetOutputToNull();
}
catch (Exception exception)
{
threadMessage = "Error doing text to speech to file: " + exception.Message;
returnValue = false;
}
});
t.Start();
t.Join();
if (!returnValue)
{
message = threadMessage;
return returnValue;
}
I saw a couple of posts for a similar problem in a service that advised doing the operation in a thread, hence the above thread.
Actually, using the SpeechSynthesizer for other things can hang as well. I had a page that just enumerated the voices, but it would get stuck as well. Since there is no user code in any of the threads if I pause the debugger, I have no clue how to debug it.
I've tried Dispose'ing the SpeechSynthesizer object afterwards, calling SetOutputToDefaultVoice, to no avail. I've tried it on both Windows 8.1 and Windows 8, running with the development server under the debugger, or running IIS Express separately.
Any ideas? Is there other information I could give that would be helpful?
Thanks.
-John
Try
Public void Speak(string wavFilePath, string text)
{
using (var synthesizer = new SpeechSynthesizer())
{
synthesizer.SetOutputToWaveFile(wavFilePath);
synthesizer.Speak(text);
return outputFile;
}
}
Task.Run(() => Speak("path", "text")).Result;
It worked for me in IIS Express
We have very weird problem with our web site. When we run our site for the first time in the day (it is not first time after deployment) it runs very slow and take 5 minutes to load the page (any browser) even if no body is connected to that site at that moment. But, once we start using it, opens various pages, it runs like a charm - very fast (not more than 4 seconds) I mean to say and even if single or multiple users are connected to it. In clear terms, if site remains idle, site performs badly for the first time but once we start using it, it runs in usual. We are using following to build the site:
MVC 4
Dot net framework 4.5
Database: SQLAnywhere and SQL Server 2008 (we have tried to use both the database to resolve the issue but no success)
Entity Framework 5.0 using Web API model and we are using jQuery call to have data on page and showing them on DataTable grid (http://www.datatables.net/)
Hosted on IIS 7.5
Note: This site was working correctly few days back but we don't know what went wrong (in code or hosting settings etc.) during last few deployments but it works very slow. We have tried with everything but now we are in need of your expert guidance.
Many thanks in advance.
My code in global.asax.cs is:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//ConfigureApi(GlobalConfiguration.Configuration);
GlobalConfiguration.Configuration.Filters.Add(new ModelValidationFilterAttribute());
FilterConfig.RegisterHttpFilters(GlobalConfiguration.Configuration.Filters);
BundleTable.EnableOptimizations = true;
}
protected void Session_Start(object src, EventArgs e)
{
SessionHelper.EnterPriceID = 1;
SessionHelper.CompanyID = 1;
SessionHelper.RoomID = 1;
SessionHelper.UserID = 1;
SessionHelper.RoomName = "Room1";
SessionHelper.UserName = "Admin";
SessionHelper.CompanyResourceFolder = SessionHelper.EnterPriceID.ToString() + "_" + SessionHelper.CompanyID.ToString();
eTurns.DTO.Resources.ResourceHelper.ResourceDirectoryPath = HttpContext.Current.Server.MapPath(#"\Resources\" + SessionHelper.CompanyResourceFolder) + #"\";
eTurns.DTO.Resources.ResourceHelper.ResourceBaseClassPath = eTurns.DTO.Resources.ResourceHelper.ResourceDirectoryPath.Replace(#"\", ".");
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = c;
Thread.CurrentThread.CurrentCulture = c;
Session["CurrentCult"] = c;
}
public void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Session != null && Session["CurrentCult"] != null)
{
string currentCulture = Convert.ToString(Session["CurrentCult"]);
if (String.Compare(currentCulture, System.Threading.Thread.CurrentThread.CurrentCulture.ToString(), StringComparison.OrdinalIgnoreCase) != 0)
{
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
try
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(currentCulture);
}
catch
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");
}
}
}
}
Increase your IDEAL TIMEOUT 20 M to 900 M (as per your convenience)....
I hope this works.....
I'm developing a web site in which the site manager can change dinamically the MetaTags for the web site in a cms, storing those MetaTags in a MySql database.
In the public master.page, in the Page_Load event, I get those MetaTags from the database
sTitle = get_from_data_base();
using (HtmlMeta mTag = new HtmlMeta())
{
mTag .Name = "Title";
mTag .Content = sTitle;
Page.Header.Controls.Add(mTag);
}
The problem is everytime a page loads, the load event of the master.page is loading from database those MetaTags.
How can I keep in cache or something similar the metatags once they have been loaded so the site doesn't access the database on every request?
How can the site knows when those MetaTags have changed to load them again?
Please, could you provide an example.
Thanks so much.
One of the solutions to do is to load the data once in the global.asax application start event and add the result in application object then in each page you need it, load it from the application object.
When the data is changed in the database, access the application object and update it as well.
If you don't know how to deal with global.asax or application object, i will post code.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
string sTitle = get_from_data_base();
Application.Add("sTitle", sTitle);
}
public string get_from_data_base()
{
//update this to call the database and get the data
return "Your data";
}
In your pages write the following:
string sTitle = Application["sTitle"].ToString();
using (HtmlMeta mTag = new HtmlMeta())
{
mTag.Name = "Title";
mTag.Content = sTitle;
Page.Header.Controls.Add(mTag);
}
While your manage is updating the metatag append the following line
Application["sTitle"] = "You manager entered string";
Finally, after your answers and reading on the Internet I went for the Cache object instead Application object. I have read is better, so my final aproach for this would be to add this on the global class and access this method from my master.pages
public static MetaTagsDN get_meta_tags()
{
MetaTagsDN oTags;
if (HttpRuntime.Cache["MetaTags"] == null)
{
MetaTagsLN ln = new MetaTagsLN();
oTags = ln.get_metatags();
HttpRuntime.Cache["MetaTags"] = oTags;
}
else
{
oTags = (MetaTagsDN)HttpRuntime.Cache["MetaTags"];
}
return oTags;
}
What do you think?
Thanks for helping me...
Im working on a example that im trying to use a webservice make it in .net c# and i have a some questions. I have a method in webservice like that:
public string login(string user, string pass)
{
//string msg = "";
string res = "";
person n = new person(user, pass);
if (n.login())
{
Session["user"] = Server.HtmlEncode(u);
setTimeOutLogIn(u);
res = u;
}
else
{
// msg = "Error";
}
return res;
}
now with this I return a string with a unique user for flex to make a state of user.
my doubt is how can I work properly on flex with session?
Other question and problem having here, and is a big one:
when is made any request to webservice the flex only answer the second ask. for example:
public function LogUser()
{
var name:String=Login.text;
var pass:String=Password.text;
Service.login.send(name, pass);
checkLogin();
}
public function checkLogin():Boolean
{
var boll:Boolean= new Boolean;
Service.checkLogin.send(util);
boll = Service.checkLogin.lastResult;
if(boll==false)
{
Llogout.visible=false;
Lregist.visible=true;
Llogin.visible=true;
Luser.visible=false;
currentState="default";
}
else
{
Llogin.visible=false;
Llogout.visible=true;
Lregist.visible=false;
Luser.visible=true;
Luser.text=util;
currentState="default";
}
return boll;
}
<s:operation name="login"> </s:operation>
<s:operation name="checkLogin" result="checkLog()"></s:operation>
</s:WebService>
this simple operation only respond rightly for the second time.
Any thoughts?
Sorry for the trouble
Webservice calls are not like website calls. You will not be able to set a user session that will persist and only be available to your users session. You may want to check out FlorineFX I dont think it will do exactly what you want but I know you can do some of this stuff and interact with the asp.net more like a website. We used this for several projects a couple years ago.